package com.neuralnoise.hibernate.geo;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;

import com.neuralnoise.geo.GeoUtils;

@Embeddable
public class GeoLocationId implements java.io.Serializable {

	private static final long serialVersionUID = 1516011543237197565L;

	private GeoUtils.ServiceType service;
	private String address;
	private String language;
	
	public GeoLocationId() { }

	public GeoLocationId(GeoUtils.ServiceType service, String address, String language) {
		this.service = service;
		this.address = address;
		this.language = language;
	}
	
	@Enumerated(EnumType.STRING)
	@Column(name = "service", nullable = false)
	public GeoUtils.ServiceType getService() {
		return service;
	}

	public void setService(GeoUtils.ServiceType service) {
		this.service = service;
	}
	
	@Column(name = "address", nullable = false, length = 64)
	public String getAddress() {
		return address;
	}
	
	public void setAddress(String address) {
		this.address = address;
	}
	
	@Column(name = "language", nullable = false, length = 8)
	public String getLanguage() {
		return language;
	}
	
	public void setLanguage(String language) {
		this.language = language;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((address == null) ? 0 : address.hashCode());
		result = prime * result
				+ ((language == null) ? 0 : language.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GeoLocationId other = (GeoLocationId) obj;
		if (address == null) {
			if (other.address != null)
				return false;
		} else if (!address.equals(other.address))
			return false;
		if (language == null) {
			if (other.language != null)
				return false;
		} else if (!language.equals(other.language))
			return false;
		return true;
	}
	
}
